<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>order管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../../static/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../../static/css/style.css">

    <!-- 上传图片框样式，不使用上传组件可以删除此样式 -->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 150px;
            height: 70px;
            line-height: 150px;
            text-align: center;
        }
        .avatar {
            width: 150px;
            height: 70px;
            display: block;
        }

    </style>
</head>
<body class="hold-transition">
<div id="app">

    <div class="content-header">
        <h1>管理<small>order管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>管理</el-breadcrumb-item>
            <el-breadcrumb-item>order管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--查询表单-->
                <el-form :inline="true" >

          <el-form-item label="用户名称">
<el-input v-model="searchMap.username" placeholder="用户名称" class="filter-item" ></el-input></el-form-item>


          <el-form-item label="收货人">
<el-input v-model="searchMap.receiverContact" placeholder="收货人" class="filter-item" ></el-input></el-form-item>
          <el-form-item label="收货人手机">
<el-input v-model="searchMap.receiverMobile" placeholder="收货人手机" class="filter-item" ></el-input></el-form-item>


          <el-form-item label="交易流水号">
<el-input v-model="searchMap.transactionId" placeholder="交易流水号" class="filter-item" ></el-input></el-form-item>



                <el-button class="dalfBut" @click="fetchData()">查询</el-button>

                </el-form>
            </div>
            <div>
                <el-button @click="deliverMany()" type="primary" size="mini" >批量发货</el-button>
            </div>

            <el-table :data="tableData" border style="width: 100%" @selection-change="changeFun">
                <el-table-column   type="selection" width="55" ></el-table-column>
                          <el-table-column prop="id" label="订单id" width="160"></el-table-column>
          <el-table-column prop="totalNum" label="数量合计" width="55"></el-table-column>


          <el-table-column prop="postFee" label="邮费" width="55"></el-table-column>
          <el-table-column  label="实付金额" width="80">
              <template slot-scope="scope">
                  ￥{{scope.row.payMoney/100}}
              </template>
          </el-table-column>




          <el-table-column  label="物流名称" width="140">
              <template slot-scope="scope">
                  <el-select v-model="scope.row.shippingName" placeholder="请选择物流"   >
                      <el-option
                              v-for="item in options"
                              :key="item.name"
                              :label="item.name"
                              :value="item.name"
                      >
                      </el-option>
                  </el-select>
              </template>

          </el-table-column>

          <el-table-column  label="物流单号" width="150">
              <template slot-scope="scope">
                  <el-input v-model="scope.row.shippingCode" placeholder="物流单号" class="filter-item" ></el-input>
              </template>
          </el-table-column>

          <el-table-column prop="username" label="用户名称" width="100"></el-table-column>

          <el-table-column prop="receiverContact" label="收货人" width="80"></el-table-column>
          <el-table-column prop="receiverMobile" label="收货人手机" width="100"></el-table-column>


          <el-table-column prop="receiverAddress" label="地址" ></el-table-column>



                    <el-table-column
                            label="操作"  width="80">
                        <template slot-scope="scope">
                            <el-button @click="save(scope.row.id,scope.row.shippingName,scope.row.shippingCode)" type="primary" size="mini" >发货</el-button>

                        </template>
                    </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @size-change="fetchData"
                        @current-change="fetchData"
                        :current-page.sync="currentPage"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="size"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>






        </div>
    </div>


</div>
</body>
<script src="../../static/js/vue.js"></script>
<script src="../../static/js/axios.js"></script>
<script src="../../static/js/elementui.js"></script>
<script>
     new Vue({
        el: '#app',
        data(){
            return {
                tableData: [],
                currentPage: 1,
                total: 10,
                size: 10,
                searchMap: {'consignStatus':'0'},
                pojo: {},
                formVisible: false,
                tableVisible:false,
                imageUrl: '',
                options: [],
                selection:[],
                obj:{},
                oderobj:[]

            }
        },
        created(){
            this.fetchData();
            this.searchFreightTemplate();
        },
        methods:{
            changeFun(val){

                this.selection=val;


            },

            searchFreightTemplate(){
                axios.get(`/freightTemplate/findAll.do`).then(response => {
                    this.options = response.data;

                // this.imageUrl=this.pojo.image //显示图片  如页面有图片上传功能放开注释
            });

            },

            fetchData (){
                axios.post(`/order/findPage.do?page=${this.currentPage}&size=${this.size}`,this.searchMap).then(response => {
                    this.tableData = response.data.rows;
                    this.total = response.data.total;
                });
            },
            save (id,shippingName,shippingCode){
                if (!shippingName) {
                    this.$message.error('请选择物流');
                    return false
                }
                if (!shippingCode) {
                    this.$message.error('请填写物流单号');
                    return false
                }
                // this.pojo.image= this.imageUrl; //如页面有图片上传功能放开注释

                axios.post(`/order/update.do`,{'id':id,'shippingName':shippingName,'shippingCode':shippingCode}).then(response => {

                    this.fetchData (); //刷新列表
                    // this.formVisible = false ;//关闭窗口
                this.$message.success('发货成功')
                });
            },
            edit (id){
                // this.formVisible = true // 打开窗口
            //
            //     axios.get(`/order/findById.do?id=${id}`).then(response => {
            //         this.pojo = response.data;
            //     // this.imageUrl=this.pojo.image //显示图片  如页面有图片上传功能放开注释
            // })
            },
            deliverMany (){
                for(var i in this.selection){
                    if(!this.selection[i].shippingName){
                        this.$message.error('请选择物流');
                        return false;
                    }

                    if(!this.selection[i].shippingCode){
                        this.$message.error('请填写物流单号');
                        return false;
                    }

                this.obj={'id':this.selection[i].id,'shippingName':this.selection[i].shippingName,'shippingCode':this.selection[i].shippingCode};
                    this.oderobj.push(this.obj);
                    this.obj={};
                }


                axios.post(`/order/deliverMany.do`,this.oderobj).then(response => {
                    this.fetchData ();
                this.$message.success('批量发货成功');
                // this.imageUrl=this.pojo.image //显示图片  如页面有图片上传功能放开注释
            })
            },

            dele (id){
                this.$confirm('确定要删除此记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then( () => {
                    axios.get(`/order/delete.do?id=${id}`).then(response => {
                        this.fetchData (); //刷新列表
                    })
                })
            },
			/* ****图片上传相关代码  如页面有图片上传功能放开注释 **** 
            handleAvatarSuccess(res, file) {
                this.imageUrl = file.response;
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            }*/
        }
    })
</script>
</html>
